<?php
/*
	账户支付
	管理端支付接口
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	cfc('core')->checklogin();
	if(!$_RQ['id']){
		exi('没有找到该考卷，请重新选择！','error','jy_kaoshi/index/');
	}
	$num=pdo_getcolumn('jy_kaoshi_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'readnum');
	$num=$num+1;
	pdo_update('jy_kaoshi_list',array('readnum'=>$num),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$item=pdo_get('jy_kaoshi_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$this->session('dati_id',$_RQ['id']);
	$canyu=pdo_get('jy_kaoshi_canyu',array('issub'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'datiid'=>$_RQ['id']));
	if($canyu['id']){
		$canyu['content']=json_decode($canyu['content'],true);
		$return['nowkey']=intval($canyu['nowkey']);
		$return['nowitem']=$canyu['content'][$return['nowkey']];
		$item['content']=$canyu['content'];
	}else{
		$item['typenum']=json_decode($item['typenum'],true);
		$tikus=$this->model('model')->gettikus($item);
		$insert=array(
			'datiid'=>$_RQ['id'],
			'allscore'=>$item['allscore'],
			'content'=>$tikus,
		);
		$canyu['id']=$this->model('model')->add_canyu($insert);
		$return['nowkey']=intval($_RQ['nowkey']);
		$item['content']=$tikus;
		$canyu['content']=$tikus;
	}
	$item['content']=array_values($item['content']);
	foreach($item['content'] as &$v){
		$v['typetitle']=$this->ti_types[$v['type']];
	}
	$return['nowitem']=$item['content'][$return['nowkey']];
	$return['allnum']=count($item['content']);
	$return['item']=$item;
	$return['banner']=json_decode($item['hdp'],true);
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['remark'],
		'link'=>custom_url('jy_kaoshi/index/detail/id='.$item['id'],true),
		'imgUrl'=>ATTACHMENT_URL.$item['image'],
	);
	set_html('title',$item['title']);
	$return['post']=array('id'=>$canyu['id'],'nowkey'=>$return['nowkey'],'content'=>$item['content']);
	$return['danan_key']=$this->danan_key;
	exi($return);
}
if($_RQ['op']=='update'){
	$postdata=get_postdata();
	if($postdata){
		$this->model('model')->up_canyu($postdata);
	}
	exi('success');
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$getscore=$this->model('model')->getscore($postdata['content']);
	pdo_update('jy_kaoshi_canyu',array('issub'=>1,'allscore'=>$getscore['allscore'],'score'=>$getscore['score'],'content'=>ijson_encode($getscore['content'])),array('uniacid'=>$_SESSION['uniacid'],'id'=>$postdata['id']));
	exi('提交答卷成功','','jy_kaoshi/ti_index//id='.$this->session('dati_id'));
}
if($_RQ['op']=='like'){
	$postdata=get_postdata();
	$like=pdo_get('jy_kaoshi_like',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ti_id'=>$id),'id');
	if($like){
			pdo_delete('jy_kaoshi_like',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ti_id'=>$id));
			exi('取消成功');
	}else{
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'ti_id'=>$id,
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_kaoshi_like',$insert);
			exi('收藏成功');
	}
}